extends AnimatedSprite2D

enum EnemyState {
	Idle,
	Walk,
	Attack,
	Death
}
# 敌人状态
var newEnemyState: EnemyState

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	self.play("Idle")
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	if newEnemyState == EnemyState.Walk:
		var horizontal: float = Input.get_axis("左", "右")
		self.position.x += horizontal
	pass
func _input(_event: InputEvent) -> void:
	if _event is InputEventKey:
		if Input.is_action_just_pressed("左"):
			if newEnemyState == EnemyState.Idle:
				newEnemyState = EnemyState.Walk
				self.set_flip_h(true)
				self.play("Walk")
		elif Input.is_action_just_released("左"):
			if newEnemyState == EnemyState.Walk:
				newEnemyState = EnemyState.Idle
				self.stop()
				self.play("Idle")

		if Input.is_action_just_pressed("右"):
			if newEnemyState == EnemyState.Idle:
				newEnemyState = EnemyState.Walk
				self.set_flip_h(false)
				self.play("Walk")
		elif Input.is_action_just_released("右"):
			if newEnemyState == EnemyState.Walk:
				newEnemyState = EnemyState.Idle
				self.stop()
				self.play("Idle")
		if Input.is_action_just_pressed("跳跃"):
			if newEnemyState != EnemyState.Death:
				newEnemyState = EnemyState.Attack
				self.play("Attack")
		elif Input.is_action_just_released("跳跃"):
			print("刚抬起了跳跃")
			newEnemyState = EnemyState.Idle
		elif Input.is_action_pressed("跳跃"):
			print("按着跳跃")
	pass
